# Makefile gnome-pulse-applet
#
# Author: Harry Karvonen <harry.karvonen@gmail.com>
#

DESTDIR =
# FIXME detection if /usr/lib64 exists use it else /usr/lib
LIBDIR = $(if $(wildcard $(DESTDIR)/usr/lib64),/usr/lib64,/usr/lib)
# FIXME detect this too
PYTHON_DIR = $(wildcard $(DESTDIR)$(LIBDIR)/python*)
PYTHON_VERSION = $(PYTHON_DIR:$(DESTDIR)$(LIBDIR)/python%=%)


# Default target
# make
all:
	$(MAKE) -C GnomePulseAppletInterface/ \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	mkdir -p locale/fi/LC_MESSAGES/
	msgfmt locale/fi.po -o locale/fi/LC_MESSAGES/gnome-pulse-applet.mo

# Install target
install: install-pulse-applet
	$(MAKE) -C GnomePulseAppletInterface/ install \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)

install-pulse-applet:
	mkdir -p $(DESTDIR)/usr/share/gnome-pulse-applet
	install gnome-pulse-applet.xml \
          $(DESTDIR)/usr/share/gnome-pulse-applet/gnome-pulse-applet.xml
	install locale/fi/LC_MESSAGES/gnome-pulse-applet.mo \
          $(DESTDIR)/usr/share/locale/fi/LC_MESSAGES/gnome-pulse-applet.mo
	install pulse-applet.py \
          $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/site-packages/pulse-applet.py
	ln -s $(LIBDIR)/python$(PYTHON_VERSION)/site-packages/pulse-applet.py \
          $(DESTDIR)/usr/bin/pulse-applet.py
	install GNOME_PulseApplet_Factory.server \
          $(DESTDIR)$(LIBDIR)/bonobo/servers/GNOME_PulseApplet_Factory.server

install-devel:
	$(MAKE) -C GnomePulseAppletInterface/ install-devel \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	ln -s $(PWD)/pulse-applet.py \
          $(DESTDIR)/usr/bin/
	ln -s $(PWD)/GNOME_PulseApplet_Factory.server \
          $(DESTDIR)$(LIBDIR)/bonobo/servers/
	mkdir -p $(DESTDIR)/usr/share/gnome-pulse-applet
	ln -s $(PWD)/gnome-pulse-applet.xml \
          $(DESTDIR)/usr/share/gnome-pulse-applet/gnome-pulse-applet.xml
	ln -s $(PWD)/locale/fi/LC_MESSAGES/gnome-pulse-applet.mo \
          $(DESTDIR)/usr/share/locale/fi/LC_MESSAGES/gnome-pulse-applet.mo

uninstall:
	$(MAKE) -C GnomePulseAppletInterface uninstall \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	$(RM) $(DESTDIR)/usr/bin/pulse-applet.py*
	$(RM) $(DESTDIR)$(LIBDIR)/bonobo/servers/GNOME_PulseApplet_Factory.server
	$(RM) $(DESTDIR)/usr/share/locale/fi/LC_MESSAGES/gnome-pulse-applet.mo
	$(RM) -r $(DESTDIR)/usr/share/gnome-pulse-applet

clean:
	$(MAKE) -C GnomePulseAppletInterface clean
